import { createRouter, createWebHashHistory } from 'vue-router'
import Test from '@/views/test'

// 公共布局页面（父路由）
const Layout = () => import('@/views/layout')
// 导入子路由页面
const Home = () => import('@/views/home')
// 分类页面
const CateGroy = () => import('@/views/categroy')
// 商品详情页面
const Detail = () => import('@/views/detail')

// 登录页
const Login = () => import('@/views/login')

// 购物车
const Cart = () => import('@/views/cart')

// 下单页面
const Order = () => import('@/views/order')

// 支付页面
const Pay = () => import('@/views/pay')

// 支付结果
const PayResult = () => import('@/views/pay/result.vue')

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/', // 地址和父路由path地址一样，默认会被加载渲染
        component: Home
      },
      {
        path: '/categroy/:id',
        component: CateGroy
      },
      {
        path: '/detail/:id',
        component: Detail
      },
      {
        path: '/cart',
        component: Cart
      },
      {
        path: '/order',
        component: Order
      },
      {
        path: '/pay',
        component: Pay
      },
      { path: '/pay/callback', component: PayResult }
    ]
  },
  {
    path: '/test',
    component: Test
  },
  {
    path: '/login',
    component: Login
  }
]

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  routes
})

export default router
